﻿using LangRenGameLib.Card.Skill;
using LangRenGameLib.Enum;
using LangRenGameLib.Times;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace LangRenGameLib
{
    /// <summary>
    /// 游戏的执行总类，负责每一场游戏的进程，
    /// </summary>
    class RunTime
    {
        /// <summary>
        /// 是哪个房间的进程
        /// </summary>
        public Room.Room Owner;

        /// <summary>
        /// 当前所处阶段
        /// </summary>
        public RoundTime Round;

        /// <summary>
        /// 当前天数，第0天即首夜
        /// </summary>
        public int Day;

        Thread RunTimeThread;

        /// <summary>
        /// 是否处于等待状态
        /// </summary>
        public bool TaskMode;

        /// <summary>
        /// 当前正在检定的技能
        /// </summary>
        public CardSkill UseSkill;

        public RunTime(Room.Room owner)
        {
            RunTimeThread = new Thread(Run);
            Round = RoundTime.Night;
            Owner = owner;
            Day = 0;
        }

        public void Start()
        {
            RunTimeThread.Start();
        }

        public void Run()
        {
            //死循环
            while (true)
            {
                //切换到夜晚
                Round = RoundTime.Night;
                //循环一百次的技能调用
                for (int i = 0; i <= 100; i++)
                {
                    foreach(Player.PlayerInfo b in Owner.Players.Players)
                    {
                        foreach(CardSkill c in b.UseCard.Skill)
                        {
                            UseSkill = c;
                            //如果真的有一个技能要触发的话进入等待
                            if (c.OnNightSkill(i))
                            {
                                TaskMode = true;
                                GetPassTime time = new GetPassTime(30);
                                time.Start();
                                while (TaskMode)
                                {
                                    if(time.Finish || !TaskMode)
                                    {
                                        TaskMode = false;
                                    }
                                }
                            }
                        }
                    }
                }
                //全部循环完后天亮检定
                
                
            }
        }
    }
}
